//
//  MoneyViewController.m
//  TengyunStation
//
//  Created by Johnny on 15/8/28.
//  Copyright (c) 2015年 xingrong. All rights reserved.
//

#import "MoneyViewController.h"
#import "MoneyDetailViewController.h"
#import "MoneyCell.h"
#import "Singleton.h"
#import "TSHeader.h"

@interface MoneyViewController ()

@end

@implementation MoneyViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"个人账户";
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self reloadTableViewData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self rightBarButtonItemTitle:@"账户明细" Method:@selector(pullMoneyDetailVC)];
    _headerView.frame = CGRectMake(0, 0, 320, 160);
    self.tableView.tableHeaderView = _headerView;
}

- (void)pullMoneyDetailVC {
    MoneyDetailViewController *moneyDVC = [[MoneyDetailViewController alloc] initWithNibName:@"MoneyDetailViewController" bundle:nil];
    [self.navigationController pushViewController:moneyDVC animated:YES];
}

- (void)reloadTableViewData {
    _moneyLabel.text = [NSString stringWithFormat:@"￥%.2f",[Singleton shareInstance].statisticsCount.allWithdraw + [Singleton shareInstance].statisticsCount.frozenMoney];
    [self.tableView reloadData];
}

#pragma mark UITableViewDataSource,UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIndentifier = @"MoneyCell";
    MoneyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIndentifier];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"MoneyCell" owner:self options:nil] lastObject];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (indexPath.row == 0) {
        cell.nameLabel.text = @"提现金额";
        cell.detailLabel.text = @"可进行提现";
        cell.moneyLabel.text = [NSString stringWithFormat:@"￥%.2f",[Singleton shareInstance].statisticsCount.allWithdraw];
    } else if (indexPath.row == 1) {
        cell.nameLabel.text = @"冻结金额";
        cell.detailLabel.text = @"正在付款中";
        cell.moneyLabel.text = [NSString stringWithFormat:@"￥%.2f",[Singleton shareInstance].statisticsCount.frozenMoney];
    } else if (indexPath.row == 2) {
        cell.nameLabel.text = @"保证金";
        cell.detailLabel.text = @"可返还";
        cell.moneyLabel.text = [NSString stringWithFormat:@"￥%.2f",[Singleton shareInstance].userMessage.margin];
    }
    return cell;
}

- (IBAction)tixianMoney:(id)sender {
    
}
@end
